package test;

import com.google.common.base.Strings;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;

import java.util.Date;

/**
 * Hello world!
 *
 */
public class App {
    public static final String YYYY_MM_DD = "yyyy-MM-dd";

    public static void main( String[] args ) {
//        if(StringUtils.isNotBlank(nPassenger.getBirthday()) && RegexUtils.isDate(nPassenger.getBirthday())){
//            birthday = DateUtils.format2Date(DateUtils.YYYY_MM_DD, nPassenger.getBirthday());
//        }

        String str ="1970-01-01";
        Date birthday =null;
        try {
            birthday =format2Date(YYYY_MM_DD, str);

        }catch (Exception ex){

            String aa="";
        }
        String a="";
    }

    public static Date format2Date(String pattern, String date) {
        if(!Strings.isNullOrEmpty(pattern) && !Strings.isNullOrEmpty(date)){
            return format(pattern, date).toDate();
        }
        return null;
    }

    public static DateTime format(String pattern, String date) {
        if (!Strings.isNullOrEmpty(date) && !Strings.isNullOrEmpty(pattern)) {
            return getFormatter(pattern).parseDateTime(date);
        }
        return null;
    }

    public static org.joda.time.format.DateTimeFormatter getFormatter(String pattern) {
        if (Strings.isNullOrEmpty(pattern)) {
            return DateTimeFormat.forPattern(pattern).withZoneUTC();
        }
        return null;
    }
}
